var e = require("../../@babel/runtime/helpers/interopRequireDefault"), t = e(require("../../@babel/runtime/regenerator")), r = require("../../@babel/runtime/helpers/asyncToGenerator"), o = e(require("../../http/offlineShop")), n = e(require("../../http/info")), a = require("../../utils/tool"), c = getApp(), s = require("../../http/userApi.js"), i = new o.default(), u = new n.default();

Page({
    data: {
        time: 200,
        orderId: "",
        orderDetail: {},
        buttonText: "",
        isZero: !1
    },
    onLoad: function(e) {
        this.setData({
            orderId: e.orderId
        }), this.getDetail();
    },
    getDetail: function() {
        var e = this;
        return r(t.default.mark(function r() {
            var o, n;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return t.prev = 0, wx.showLoading({
                        title: "加载中",
                        mask: !0
                    }), o = {
                        orderId: e.data.orderId
                    }, t.next = 5, i.checkOfflineShopOrder(o);

                  case 5:
                    n = t.sent, e.setData({
                        orderDetail: n.data,
                        buttonText: 0 == n.data.orderTotalAmount ? "确认订单" : "支付",
                        isZero: 0 == n.data.orderTotalAmount
                    }), t.next = 11;
                    break;

                  case 9:
                    t.prev = 9, t.t0 = t.catch(0);

                  case 11:
                    return t.prev = 11, wx.hideLoading(), t.finish(11);

                  case 14:
                  case "end":
                    return t.stop();
                }
            }, r, null, [ [ 0, 9, 11, 14 ] ]);
        }))();
    },
    tappingPay: function() {
        this.data.isZero ? this.zeroPay() : this.pay();
    },
    zeroPay: function() {
        var e = this;
        return r(t.default.mark(function r() {
            var o;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return t.prev = 0, wx.showLoading({
                        mask: !0,
                        title: "加载中"
                    }), o = {
                        orderNo: e.data.orderDetail.orderNo,
                        payWay: 1
                    }, t.next = 5, i.zeroPayOfflineShopOrder(o);

                  case 5:
                    t.sent, (0, a.toastToPage)("确认订单成功"), e.toShopSuccess(), t.next = 12;
                    break;

                  case 10:
                    t.prev = 10, t.t0 = t.catch(0);

                  case 12:
                    return t.prev = 12, wx.hideLoading(), t.finish(12);

                  case 15:
                  case "end":
                    return t.stop();
                }
            }, r, null, [ [ 0, 10, 12, 15 ] ]);
        }))();
    },
    pay: function() {
        var e = this;
        return r(t.default.mark(function r() {
            var o, n, c, s;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return t.prev = 0, wx.showLoading({
                        mask: !0,
                        title: "加载中"
                    }), t.next = 4, (0, a.getWechatLoginCode)();

                  case 4:
                    return o = t.sent, t.next = 7, u.getOpenId({
                        code: o
                    });

                  case 7:
                    return n = t.sent, c = {
                        orderNo: e.data.orderDetail.orderNo,
                        userId: n.data.openId,
                        payWay: 1
                    }, t.next = 11, i.payOfflineShopOrder(c);

                  case 11:
                    s = t.sent, (0, a.callWeChatPay)(s.data.miniPayRequest, e.toShopSuccess, e.cancelPay), 
                    t.next = 17;
                    break;

                  case 15:
                    t.prev = 15, t.t0 = t.catch(0);

                  case 17:
                    return t.prev = 17, wx.hideLoading(), t.finish(17);

                  case 20:
                  case "end":
                    return t.stop();
                }
            }, r, null, [ [ 0, 15, 17, 20 ] ]);
        }))();
    },
    toShopSuccess: function() {
        var e = this, t = "MB3dRY6WLJhC1kSxHEjspgF3fHrRuB5UXt2_x9gfVpw", r = "y_AzBJRhjemy0g9tmVA366OK-lmxg1P4Qb_CEHFSlTc";
        wx.requestSubscribeMessage({
            tmplIds: [ t, r, "BVtYipN8LQAhbg-3jj9IRebcNsz4RG0gnmcKPeuN0Ng" ],
            success: function(o) {
                console.log("success:", o), "accept" == o[t] && (console.log("pointLoseTempl"), 
                s.subscribeNotice(2).then(function(e) {
                    console.log("pointLoseTempl success:", e);
                }).catch(function(e) {
                    console.log("pointLoseTempl error:", e);
                })), "accept" == o[r] && (console.log("pointAddTempl"), s.sendIntegrationChangeSubscribe({
                    orderType: 1,
                    orderId: e.data.orderDetail.orderId
                }).then(function(e) {
                    console.log("pointAddTempl success:", e);
                }).catch(function(e) {
                    console.log("pointAddTempl error:", e);
                })), "accept" == o["BVtYipN8LQAhbg-3jj9IRebcNsz4RG0gnmcKPeuN0Ng"] && (console.log("newProductTempl"), 
                s.subscribeNotice(4).then(function(e) {
                    console.log("newProductTempl success:", e);
                }).catch(function(e) {
                    console.log("newProductTempl error:", e);
                }));
            },
            fail: function(e) {
                console.log("fail:", e);
            },
            complete: function(e) {
                console.log("complete:", e), c.data.offlinePaySuccess = 2, wx.reLaunch({
                    url: "/pages/index/index"
                });
            }
        });
    },
    cancelPay: function() {
        (0, a.toastToPage)("用户取消支付");
    }
});